package com.ruoyi.system.controller;

//import com.ruoyi.common.annotation.Log;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
//import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.UsrUs;
import com.ruoyi.system.service.IUsrUsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
//import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户Controller
 * 
 * @author ruoyi
 * @date 2025-07-30
 */

@RestController
@RequestMapping("/system/us")
public class UsrUsController extends BaseController
{
    @Autowired
    private IUsrUsService usrUsService;

    @Value("${image.upload.path:D:/test/}")
    private String imageUploadPath;

    /**
     * 查询用户列表
     */

    @GetMapping("/list")
    public TableDataInfo list(UsrUs usrUs)
    {
        startPage();
        List<UsrUs> list = usrUsService.selectUsrUsList(usrUs);
        return getDataTable(list);
    }

    /**
     * 导出用户列表
     */

    @PostMapping("/export")
    public void export(HttpServletResponse response, UsrUs usrUs)
    {
        List<UsrUs> list = usrUsService.selectUsrUsList(usrUs);
        ExcelUtil<UsrUs> util = new ExcelUtil<UsrUs>(UsrUs.class);
        util.exportExcel(response, list, "用户数据");
//        usrUsService.exportexcel(response, usrUs);
    }

    /**
     * 获取用户详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(usrUsService.selectUsrUsById(id));
    }

    /**
     * 新增用户
     */

    @PostMapping
    public AjaxResult add(@RequestBody UsrUs usrUs)
    {
        return toAjax(usrUsService.insertUsrUs(usrUs));
    }

    /**
     * 修改用户
     */

    @PutMapping
    public AjaxResult edit(@RequestBody UsrUs usrUs)
    {
        return toAjax(usrUsService.updateUsrUs(usrUs));
    }

    /**
     * 删除用户
     */

	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(usrUsService.deleteUsrUsByIds(ids));
    }


    @PostMapping("/import")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        return usrUsService.importData(file, updateSupport);
    }

    @PostMapping("/word")
    public void exportWord(HttpServletResponse response,UsrUs param) {
        usrUsService.exportWord(response, param);
    }



    @PostMapping("/pdf")
    public void exportPdf(HttpServletResponse response,UsrUs param) {
        usrUsService.exportPdf(response, param);
    }



}
